Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract Profile - Contrast enhancement -- Selective Editing Cam16 and JzCzHz - improvments #7111

Merged
merged 192 commits into from
Jan 19, 2025

Conversation

Desmis
Copy link
Collaborator

@Desmis Desmis commented Jun 23, 2024

Contrast Enhancement

Purpose
This module complements the Tonal Response Curve (TRC) in the Abstract Profile (Color tab) and allows the user to carry out tonal contrast adjustments.

Is tonal contrast a difficult concept?
Traditionally, any graphics software can be used to retouch contrast. Empirically, this can be translated as modifying the difference in luminosity between the light and dark parts of an image.
There are various algorithms some of which may or may not take into account the following:

  • the dynamic range ;
  • the whole or just part of the image (using masks or spots).

Contrast acts on the luminance channel, whether in RGB (or its HSV derivatives, etc.) or Lab mode. and can be modified using various tools of varying complexity, linear or non-linear. For example by using functions such as log encoding, Laplacians, wavelets, guided filters, tone curves, sigmoid curves etc.

The special case of wavelets:
Wavelets are a little-known mathematical tool that is not widely used as such in image-processing software but can be the basis for other tools. Rawtherapee is, to my knowledge, the only one to have a coherent and grouped set of tools using wavelets. Unfortunately, the whole package may seem complex and off-putting.
Extensive information about the principles of wavelets and the various tools can be found in RawPedia so I won’t repeat the information here. To summarise:

  • The image details are decomposed into groups of pixels, sorted according to their size (from 2x2 up to 1024x1024 pixels if the system allows it), and distributed across the wavelet decomposition levels (one size per level). The details in each level are then assigned values which correspond to the amount of contrast in each detail (i.e. in each group of pixels) and are only generated if there is a variation between neighbouring pixels (in R,G,B or L,a,b mode).
    They are then sorted according to whether the values are positive or negative for the horizontal, vertical and diagonal directions. The decomposition method used allows the user to choose the number of Daubechies vanishing moments, which affect the quality and finesse of the decomposition.
  • The undecomposed part, which no longer has any variations in the values of neighbouring pixels (beyond the maximum value chosen by the user), constitutes the residual image and can be processed using the same tools as a traditional image.

The following tools are available in Rawtherapee:

  • Contrast by level -this tool can be found in various forms in:
    -The Selective Editing tab
    -Local Contrast & Wavelets > Pyramid 2 > Contrast by level
    -Contrast by Detail Levels
    -The Advanced tab (Advanced > Wavelet Levels > Contrast)
    -The Detail tab (Contrast by Detail Levels)
    It allows you to modify the contrast values of each group of pixels on a per-level basis in each of the 3 directions and for both the positive and negative values. However visible artefacts can appear fairly quickly (noise, blurring, distortion, sculpting effects, etc.) even when taking measures such as progressively reducing the strength of the action for high levels of detail. Additional tools can be used to reduce - but not eliminate - these artefacts (“Attenuation response”, “Selective luminance range”, etc.).

  • Edge sharpness (Advanced > Wavelet Levels and in Selective Editing > Local Contrast & Wavelets) is used both to reinforce edges, similar to the methods used in sharpening tools, and to soften backgrounds (similar to tools such as darktable's “diffuse or sharpen”). Refer to RawPedia for details.

  • Other tools such as Clarity and “Blur levels” (both in Advanced > Wavelet Levels and in Selective Editing > Local Contrast & Wavelets) etc., allow effects that virtually only wavelets can provide.

  • Local contrast: faced with the problems inherent in contrast by level, I decided a few years ago (around 2013) to take a different approach to wavelet contrast. For each level and direction, I evaluate the shape of the signal (average, standard deviation, maximum for positive and negative values). The whole thing is modelled in such a way that the user is faced with a single curve for modifying the contrast, whatever the level. This curve uses the characteristics of the signal to position the mean value at the centre of the graph, take into account the variations on either side of the mean and position the maximum at the far right of the graph. It weakens the action for large values close to the maximum. The system's behaviour avoids the majority of artefact problems, and acts in a fairly similar way across the different levels of detail. I've called this approach 'Local contrast', but this doesn't really convey what it does. This tool is present in Rawtherapee in the Wavelet Levels > Final Touchup module, in several other modules such as Wavelet Levels > “Edge sharpness” and in Selective Editing > Local Contrast & Wavelets. It can also be found in ART.
    Curiously, until now this tool has not been available separately in the tools available in full-image mode.

Variable contrast
However, despite this improvement, the system cannot, at the same time, and with the same quality as seen from the user's point of view, process the levels containing small details (from 0 to around 6) and those containing large details (from around 5 to 9) in the same way.This is why I propose to combine the action of the two systems (“Contrast by levels” and Local Contrast) into a single system.

In this new system, which I have called Contrast Enhancement, per-level contrast is contained in a series of contrast-profile presets, which provide the information needed to adjust the amount of local contrast in each of the levels.

Each preset contains a selection of decomposition levels.
In each of these levels, the contrast values are divided up into ten discrete samples ranging from the lowest to the highest values. The low-contrast-value samples and the high-contrast-value samples (which are often synonymous with artifacts) are then attenuated. The nature and intensity of this attenuation depends on the preset and whether or not "Highlight attenuation" has been activated.
Each preset also contains information used to weight the overall level data to either attenuate the data for the first level (to reduce noise) or to progressively attenuate it for the higher levels.
-the resulting data from each decomposition level is then sent to the curve, which should be preferably “bell shaped” to concentrate the action on the useful levels and attenuate the action at the extremities.

The Contrast Enhancement module has the following characteristics:

  • it works on the whole image,
  • it differentiates the action according to the existing contrast values of the detail levels,
  • it avoids artefacts by reducing the action on the upper and lower contrast values in each pixel group.
  • it introduces the notion of “Variable contrast”, which allows the user to control the areas (small, large, dark or light) where they want to modify the sharpness, structure and differentiation of the highlights, with the minimum number of commands and in the most intuitive way possible, without having to master the mathematical concepts and language of wavelets.
    What does this tool consist of?
    It consists of three parts:
    A “Contrast profile” slider that lets you select several contrast-profile presets as described above.These presets offer a selection of possible degrees of contrast.

These presets are classified :

  • from the least aggressive, corresponding essentially to the lower settings of the Contrast by Detail Levels tool, with the number of detail levels limited to 6, and an attenuated first level to take account of noise.
  • to the most aggressive, going so far as to use the maximum possibilities of the system (memory, size of the Preview).
    At the same time, these presets progressively weaken the action of the “Variable contrast” curve as you move the “Contrast profile” slider to the right.

The “Variable contrast” curve , which is the heart of the system, is used to modify the existing contrast values, based on the size of the pixel groups, their contrast and possible artefacts. The information contained in the presets determines the behaviour of the curve. However, whatever the preset and the level of detail: a) the mid-point of the x-axis corresponds to the most important contrast value for the action; b) the maximum point, to the right of x-axis, corresponds to the maximum contrast found. It is recommended to reduce the variable contrast beyond the mean value.

A Refinement expander, which can be used to modify: a) the distribution of the action between the low, medium and high values of the “Variable contrast” curve, in particular by widening or narrowing the effects of the width of the curve; b) adjust the residual image after decomposition to compensate for excessive effects linked to the action of the curve and the presets.

Moving the Color Management module
The Color Management module (which includes the Abstract Profile) has been moved up in the Color tab and positioned just after the White Balance module. This is to improve it’s visibility and to take into account the fact that it is likely to be used more frequently.

Selective Editing Cam16
In Source Data Adjustments > Highlight attenuation & RGB channels, The RGB Channel Slope module has been improved to better use the tone mapping algorithm.

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 14, 2025

@Lawrence37
To have "peace" between us, even if I am totally against it - in this case - (and the bug clearly shows that a priori no one or almost no one has used it), I will see what I can do, even if you correct my code with ppversion. But for me, it makes no sense and even the opposite is harmful.

For example, during the "Challenge" in spring 2024, which focused on this Cam16 module, no one used these features and no one saw that there were bugs,, and yet 6 users who cannot be described as "amateurs" tested Cam16 and SDA for more than 1 month...

Cordially.

Jacques

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 14, 2025

@Lawrence37 @waynesutton50

As agreed, and even if I think it's a mistake, I changed "procparams.cc" taking into account "ppversion < 352"

Three groups of variables are concerned:

  • logcieq - which allowed in 5.11 to have the Brightness Q version of Log encoding (in the loop Ciecam)
  • sigq - which allowed in 5.11 - for Brightness Q (in the loop Ciecam), to use the old Sigmoid Q algorithm
  • sigjz - which allowed in 5.11 - for Brightness J (in JzCzHz), to use the old Sigmoid J algorithm

I tested with the 2 pp3 files you attached "Cam16.pp3" and "Jzazbz.pp3". It seems to work. But as these manipulations are not my strong point, you can check and modify if necessary.

I also changed the ModeQJ toolip which no longer has any reason to exist in its old form.

Cordially

Jacques

@Lawrence37
Copy link
Collaborator

Thanks, I confirm the pp3s result in the same output between 5.11 and this PR.

I assure you that this is not a mistake. Here's why. There are two possible scenarios when someone opens an old edit. First, they are fine with what the old algorithm did. In this scenario, there is no point in forcing them to use a different algorithm because the results are already satisfactory. Second, they want to tweak the edit or start fresh. In this scenario, the processing parameters have changed. Backward compatibility is no longer relevant. You are free to prevent them from going back to the old algorithms. There is no disagreement between us because my only concern is the backward compatibility.

So really, only the first scenario restricts what you can do, and I doubt anyone can come up with a good argument why a user isn't actually satisfied with an edit whey they think they are satisfied.

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 15, 2025

@Lawrence37 @waynesutton50

OK, thank you, this confirms that I was not mistaken...

I am waiting, today or tomorrow, for comments on Laels and Tooltips from Wayne

Then I think you will agree to "merge" with dev? (I hope)

Thank you

Jacques

@waynesutton50
Copy link

waynesutton50 commented Jan 15, 2025

@Desmis Jacques, In the “Cam16” CAM model the tooltip TP_LOCALLAB_QJMODE_TOOLTIP Vous permet de choisir, pour les opérateurs tone-mapping utilisant les données Brightness : Q pour Cam16 - et J pour Jz, entre la version courante (recommandée) 5.12 et les versions antérieures 5.11.
implies that there are changes in the behaviour of the “Tone mapping operators *” further down in the menu (just under the TRC) , however after playing around with the settings, I suspect that it refers in fact to the Sigmoid Q/ Sigmoid Q & Slope based menus just prior to Viewing Conditions. Is this the case?
A few other remarks not related to the tooltip.

  • in the JzCzHz CAM model mode the tone mappers are in the Scene Conditions menu whereas in the “Cam 16” mode they are in Source Data Adjustments menu (which doesn’t exist in the JzCzHz mode). Should there be consistency between the Cam16 and JzCzHz menus?
  • if you check the Log Encoding Jz checkbox and switch between 5.11 and 5.12, the box stays checked which is not the case if you check the Sigmoid Jz checkbox and change between 5.11 and 5.12.
  • I’m not sure that it's necessary to differentiate the 5.11 and 5.12 Sigmoid Jz labels with an asterisk (same remark for "Tone mapping operators*".
  • There are a few inconsistencies in the use of sentence case for some of the sliders. e.g. Hue Rotation should be “Hue rotation” and Threshold Chroma should be “Threshold chroma”.
  • You could maybe shorten the "Log Encoding Q - with CIECAM - Deprecated" label to "Log Encoding Q with CIECAM (deprecated)"

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 15, 2025

@waynesutton50
Thanks for these comments, I will answer you more precisely tomorrow.

It is obvious that this "addition" of 5.11 compatibility with different algorithms is not easy to explain in a tooltip.

For Cam16, for Sigmoid this only concerns the Sigmoid Q part "in the Ciecam loop" -Cam16 Image Adjustments

  • with 5.11 => Sigmoid Q - deprecated
  • with 5.12 ==> Sigmoid Q & Slope based

The 2 Sigmoid algorithms are different

The new part brought since 5.12 in SDA remains the same (5.11 or 5.12) with the menu "Tone mapping operators *" with choices : none, Ev based, Gamma based, Slope based, RGB channel slope, Sigmoid Based . Sigmoid base has been added with 5.12 but is not affected by the tooltip

For Cam16 and Log encoding in SDA (Source Data Adjustments) version 5.11 is seen with one more choice:
Log encodind Q - with Ciecam - Deprecated - which was removed in 5.12, as unreliable

For JzCzHz the difference is only Sigmoid Jz in "Scene conditions" - the algorithms and settings are different

I have taken note of your remarks and thank you for them and will continue tomorrow morning.

Jacques

@Lawrence37
Copy link
Collaborator

@Desmis There is one comment I made about using a unique pointer. Let me know when I can push the code to address the comment.

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 16, 2025

@waynesutton50
In french : la phrase du tooltip pourrait s'enrichir des commentaires suivants. Tu peux adapter - aussi bien le français, que évidemment l'anglais

====
Vous permet de choisir, pour les opérateurs tone-mapping utilisant les données Brightness : Q pour Cam16 - et J pour Jz, entre la version courante (recommandée) 5.12 et les versions antérieures 5.11 (obsolètes). Ces versions sont incompatibles entre elles.

  • pour Cam16 les procédures concernées sont :
    ** dans Cam16 Image Adjustments, pour Sigmoid Q : Sigmoid Q & Slope based pour 5.12, et Sigmoid Q (deprecated) pour 5.11.
    ** dans Source Data Adjustments, pour Log Encoding Q, une case à cocher Log encoding Q with CIECAM (deprecated), n'apparaît que pour 5.11

  • pour JzCzHz , les procédures concernées sont dans Scene Conditions : Sigmoid Jz pour 5.12 et Sigmoid Jz (deprecated) pour 5.11

Les autres variables et fonctions dans Cam16, situées dans Source Data Adjustments : Log Encoding ou Tone mapping operators utilisent toutes les données RGB.

=====

  • if you check the Log Encoding Jz checkbox and switch between 5.11 and 5.12, the box stays checked which is not the case if you check the Sigmoid Jz checkbox and change between 5.11 and 5.12.

Log encoding Jz is not concerned by this change, only Sigmoid Jz

  • Should there be consistency between the Cam16 and JzCzHz menus?

I don't think so. Cam16 is a real CAM (Color Appearance Model), which JzCzHz is not.
I think we used the term "Source Data Adjustments" together to get the idea of ​​a process upstream of Cam16 Image adjustments, but which is not exactly "Scene conditions".
In the case of JzCzHz, we are well upstream of the main process and even if JzCzHz is not a CAM, I have assigned it CAM functions, like Scene conditions, and Surround.
So I think it is correct (or acceptable depending on what we perceive)

I made the changes you suggested and harmonized in the "deprecated" Labels by putting it in parentheses. (deprecated)

In French
Reste la traduction et/ou la compréhension du tooltip relatif à Display White point (cd/m2)
TP_LOCALLAB_SIGMOIDNORMCIEDISP_TOOLTIP;(provisional).
“Adapte le point blanc à destination du périphérique de sortie pour le rendre compatible avec son pic de luminance. Cette fonctionnalité, n’est pas à l’endroit souhaité du pipe-line, car trop éloigné du processus output final. Donc à utiliser avec précautions”.

Ce slider ménage l'avenir, il suppose un moniteur HDR (ou très performant). Malheureusement actuellement, les profils de sortie vers les moniteurs - au moins ceux présents dans RT - sont en Lab 8 bits, donc incapables d'utiliser pleinement ces données. On peut dire la même chose en grande partie pour le module JzCzHz

Thank you

Jacques

@waynesutton50
Copy link

@Desmis @Lawrence37
Here are the suggested translations for the two tooltips. I'd recommend putting the additional comments and recommendations in the documentation to keep the tooltips relatively short.

TP_LOCALLAB_QJMODE_TOOLTIP;The tone-mapping operators that use brightness data (Q for CAM 16 and J for Jz) have been modified in RawTherapee version 5.12. This allows you to select either the current or the deprecated version.

TP_LOCALLAB_SIGMOIDNORMCIEDISP_TOOLTIP;Allows you to adapt the white point to the peak luminance of the display device. Its position in the processing pipeline is not optimal so use with caution.

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 16, 2025

@waynesutton50

Thank you, I will update this afternoon :)

Jacques

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 16, 2025

@Lawrence37

No problem, you can push your change about using a unique pointer.

:)

Jacques

@Lawrence37
Copy link
Collaborator

@Desmis I added the commit.

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 17, 2025

@Lawrence37
After thinking, I changed in RT all the terms Cam16 and Cam02 to CAM16 and CAM02, to respect the standards, even if the modifications made at the algorithm level mean that it is not CAM16

I also tried to better take into account the recommendations of Rawpedia (allways down) for respecting uppercase (U) and lowercase (L) in Frames, checkboxes, etc. I also tried in these modifications to update the tooltips with these same modifications. But nothing is perfect.

I don't think I have to make any more changes to this PR

My computer returned from repair after a power surge (motherboad burned) is working very poorly, I returned it to the manufacturer, and so I am still with my (very) old machine

Jacques

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 18, 2025

I think, after this big review on Labels, tooltips, convention, etc. that I finished

@Desmis
Copy link
Collaborator Author

Desmis commented Jan 19, 2025

@Lawrence37

OK thank you.

I will merge soon :)

@Desmis Desmis merged commit a578423 into dev Jan 19, 2025
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Something could be better than it currently is
Projects
None yet
3 participants